package com.echo.fm.content.systemAction;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.echo.fm.content.systemAction.model.SystemAction;
import com.echo.fm.platform.database.IHibernatePersistence;
import com.echo.util.ErrorException;

@Repository("systemActionPersistence")
public class DaoSystemActionPersistencImpl implements ISystemActionPersistence {
	@Autowired
	@Qualifier("hibernatePersistence")
	private IHibernatePersistence hibernatePersistence;

	public void setHibernatePersistence(IHibernatePersistence hibernatePersistence) {
		this.hibernatePersistence = hibernatePersistence;
	}

	public void createSystemAction(SystemAction systemAction) throws ErrorException {

		hibernatePersistence.create(systemAction);
	}

	public void deleteSystemAction(SystemAction systemAction) throws ErrorException {
		hibernatePersistence.delete(systemAction);

	}

	public void updateSystemAction(SystemAction systemAction) throws ErrorException {
		hibernatePersistence.update(systemAction);

	}

	public SystemAction searchSystemActionById(String id) throws ErrorException {
		Object object = hibernatePersistence.searchById(SystemAction.class, Restrictions.eq("id", id));
		if (object instanceof SystemAction) {
			return (SystemAction) object;
		}

		return null;
	}

	public List<SystemAction> searchSystemActionList(List<Criterion> criterions) throws ErrorException {
		@SuppressWarnings("unchecked")
		List<SystemAction> systemActionList = (List<SystemAction>) hibernatePersistence.searchList(SystemAction.class,
				criterions);
		return systemActionList;
	}

	public List<SystemAction> pagesSystemActionList(List<Criterion> criterions) throws ErrorException {
		@SuppressWarnings("unchecked")
		List<SystemAction> systemActionList = (List<SystemAction>) hibernatePersistence.searchList(SystemAction.class,
				criterions, Order.asc("id"));

		return systemActionList;
	}

	public List<SystemAction> pagesSystemActionList(List<Criterion> criterions, int firstResult) throws ErrorException {
		@SuppressWarnings("unchecked")
		List<SystemAction> systemActionList = (List<SystemAction>) hibernatePersistence.pagesList(SystemAction.class,
				criterions, Order.asc("id"), firstResult);

		return systemActionList;
	}

	public int pageSystemActionCount(List<Criterion> criterions) throws ErrorException {

		return hibernatePersistence.pagesCount(SystemAction.class, criterions);
	}

}
